/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package persistencia;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import modelo.Proveedores;
import com.mysql.jdbc.Connection;
import java.sql.DriverManager;

/**
 *
 * @author Victor
 */
public class BaseDatos {
    private String cadenaConexion;
    private String driver;
    private com.mysql.jdbc.Connection c;

    public BaseDatos(){
    }
    /**
     * 
     * @param cx cadena de conexión
     * @param d driver
     */
    public BaseDatos(String cx, String d){
            cadenaConexion=cx;
            driver=d;
    }
    /**
     * 
     * @param cx cadena de conexión
     * @param d driver
     */
    public void abrir(String cx,String d){
            cadenaConexion=cx;
            driver=d;
            abrir();
    }
    
    public String abrir(){
            try
            {
                    Class.forName(driver);
            }
            catch (ClassNotFoundException e)
            {
                    e.printStackTrace();
                     return e.getMessage();

            }
            try
            {
                    c= (com.mysql.jdbc.Connection)DriverManager.getConnection(cadenaConexion,"root","");
            }
            catch (SQLException e )
            {
                    e.printStackTrace();
                    return e.getMessage();

            }
    return "";
    }
    public String cerrar() throws SQLException{
        c.close();
    return null;
    }
    public Connection getConexion(){
            return c;
    }
  
}
